home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 26 / macformat_26.iso / Los 50 mejores / Mejoras del sistema / Smart Scroll / for Developers / SmartScrollAPI.c < prev    next >
Text File  |  1996-09-27  |  4KB  |  131 lines

  1. /*
  2.      File:        SmartScrollAPI.c
  3.  
  4.      Contains:    Smart Scroll Application Programming Interface code
  5.  
  6.      Version:    1.2
  7.  
  8.      Copyright:    © 1996 by Marc Moini, portions by Marc Menschenfreund,
  9.                 Alessandro Levi Montalcini and Mark Shirley (Thanks!)
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, please email Marc@Kagi.com
  13.  
  14. */
  15. #ifndef __SMARTSCROLLAPI__
  16. #include "SmartScrollAPI.h"
  17. #endif
  18.  
  19. #if PRAGMA_ALIGN_SUPPORTED
  20. #pragma options align=mac68k
  21. #endif
  22.  
  23. #if PRAGMA_IMPORT_SUPPORTED
  24. #pragma import on
  25. #endif
  26.  
  27. #define    kgestaltSmartScroll    'MMBS'
  28.  
  29. enum
  30.     {
  31.     kSetSmartScrollInfo = 0L,
  32.     kSetSmartScrollProp,
  33.     kGetSmartScrollProp,
  34.     kDisposeAllSmartScrolls
  35.     };
  36.  
  37. typedef pascal void (*SmartScrollProcPtr) (long selector,long *result,ControlRef theScrollBar,long param1,long param2);
  38.  
  39. typedef struct {
  40.     char                privateStuff[16];
  41.     SmartScrollProcPtr    dispatchProc;
  42.     long                smartScrollSignature;
  43. } SmartScrollGestaltRec, *SmartScrollGestaltPtr;
  44.  
  45.  
  46. #if GENERATINGCFM
  47. #define CallSmartScrollProc(userRoutine, selector, result, theControl, param1, param2)        \
  48.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSmartScrollProcInfo, (selector), (result), (theControl), (param1), (param2))
  49. #else
  50. #define CallSmartScrollProc(userRoutine, selector, result, theControl, param1, param2)        \
  51.         (*(userRoutine))((selector), (result), (theControl), (param1), (param2))
  52. #endif
  53.  
  54. enum    {
  55.     uppSmartScrollProcInfo = kPascalStackBased
  56.         | STACK_ROUTINE_PARAMETER (1, SIZE_CODE(sizeof(long)))
  57.         | STACK_ROUTINE_PARAMETER (2, SIZE_CODE(sizeof(long *)))
  58.         | STACK_ROUTINE_PARAMETER (3, SIZE_CODE(sizeof(ControlRef)))
  59.         | STACK_ROUTINE_PARAMETER (4, SIZE_CODE(sizeof(long)))
  60.         | STACK_ROUTINE_PARAMETER (5, SIZE_CODE(sizeof(long)))
  61. };
  62. /****************************************************************************************/
  63.  
  64. static OSErr __SmartScrollDispatch(long selector,long *result,ControlRef theControl,long param1,long param2)
  65.     {
  66.     OSErr                     ret = paramErr;
  67.     SmartScrollGestaltPtr    ssRec;
  68.     
  69.     if (NGetTrapAddress (_Gestalt, OSTrap) != NGetTrapAddress (_Unimplemented, OSTrap))
  70.         {
  71.         if (Gestalt ( kgestaltSmartScroll, (long *)&ssRec)==noErr
  72.             && ssRec && ssRec->smartScrollSignature==kgestaltSmartScroll)
  73.             {
  74.                 CallSmartScrollProc(ssRec->dispatchProc,selector,result,theControl,param1,param2);
  75.                 ret = noErr;
  76.             }
  77.         }
  78.     return ret;
  79.     }
  80.     
  81. /****************************************************************************************/
  82. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  83. /*  amountVisible is a 32bit value representing the size of the portion of the document that is visible now. */
  84. /*  amountTotal is a 32bit value representing the size of the whole document. */
  85. /*  these two parameters must share the same unit (pixels, lines, characters, frames, etc). */
  86.  
  87. pascal void SetSmartScrollInfo (ControlRef theScrollBar, long amountVisible , long amountTotal)
  88.     {
  89.     long     dummy;
  90.     
  91.     (void)__SmartScrollDispatch(kSetSmartScrollInfo,&dummy,theScrollBar,amountVisible,amountTotal);
  92.     }
  93.  
  94. /****************************************************************************************/
  95. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  96. /*  proportion is a Fract value (32bit) representing the Visible/Total ratio */
  97. /*  This call has the exact same effect as SetSmartScrollInfo, you may use either one. */
  98.  
  99. pascal void SetSmartScrollProp (ControlHandle theScrollBar, Fract proportion)
  100. /*
  101. Comment
  102. */
  103.     {
  104.     long     dummy;
  105.     
  106.     (void)__SmartScrollDispatch(kSetSmartScrollProp,&dummy,theScrollBar,(long)proportion,0);
  107.     }
  108.  
  109. /****************************************************************************************/
  110. /* Call this routine to get the last proportion you stored for this scrollbar. */
  111. /* the value returned will be 0 if there is an error (Smart Scroll not installed, or no value stored)  */
  112.  
  113. pascal Fract GetSmartScrollProp (ControlHandle theScrollBar)
  114.     {
  115.     Fract     result = 0L;
  116.     
  117.     __SmartScrollDispatch(kGetSmartScrollProp,(long *)&result,theScrollBar,0,0);
  118.     return result;
  119.     }
  120.  
  121. /****************************************************************************************/
  122. /* Call this routine before your code Quits, to help SmartScroll */
  123. /* free the memory it reserved for the scrollbars in your Application. */
  124.  
  125. pascal void DisposeAllSmartScrolls (void)
  126.     {
  127.     long     dummy;
  128.     
  129.     (void)__SmartScrollDispatch(kDisposeAllSmartScrolls,&dummy,NULL,0,0);
  130.     }
  131.